<?php
/**
 * curl POST请求
 * @param  $url     url地址
 * @param  $data    数据
 * @return array
 */
 function postDataCurl($url,$data){
    $timeout = 5000; 
    $http_header = array(
        'AppKey:'.'jiangyongpwd',
        'Nonce:'. 'nonce',
        'CurTime:'. time(),
        'CheckSum:'.sha1('jiangyongpwd' . 'nonce'. time()),
        'hellow:'. 'world',
        'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
    );
    //print_r($http_header);

    // $postdata = '';
    $postdataArray = array();
    foreach ($data as $key=>$value){
        array_push($postdataArray, $key.'='.urlencode($value));
        // $postdata.= ($key.'='.urlencode($value).'&');
    }
    $postdata = join('&', $postdataArray);

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt ($ch, CURLOPT_HEADER, false );
    curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); //´¦ÀíhttpÖ¤ÊéÎÊÌâ 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($ch); 
    if (false === $result) {
        $result =  curl_errno($ch);
    }
    curl_close($ch);   
    return $result;
}


$url = 'http://localhost/phponly/url/response.php';
$data= array(
    'callerAcc' => 'yuedan',
    'caller' => '18518488785',
    'callee' => '13141241232',
    'maxDur' => '60'
);
$result = postDataCurl($url,$data);
echo $result;

